using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerAnimation : MonoBehaviour
{
  // Start is called before the first frame update
  private Animator anim;
  private Rigidbody2D rb;
  private PhysicCheck phycheck;
  private PlayerController plc;

  /// <summary>
  /// Awake is called when the script instance is being loaded.
  /// </summary>
  private void Awake()
  {
    anim = GetComponent<Animator>();
    rb = GetComponent<Rigidbody2D>();
    phycheck = GetComponent<PhysicCheck>();
    plc = GetComponent<PlayerController>();
  }

  /// <summary>
  /// Update is called every frame, if the MonoBehaviour is enabled.
  /// </summary>
  private void Update()
  {
    SetAnimation();
  }

  public void SetAnimation()
  {
    anim.SetFloat("velocityX", Mathf.Abs(rb.velocity.x));
    anim.SetFloat("velocityY", rb.velocity.y);
    anim.SetBool("isGround", phycheck.isGround);
    anim.SetBool("isCrouch", plc.isCrouch);
    anim.SetBool("isDead", plc.isDead);
    anim.SetBool("isAttack", plc.isAttack);
  }

  public void PlayHurt()
  {
    anim.SetTrigger("hurt");
  }

  public void PlayAttack()
  {
    anim.SetTrigger("attack");
  }


}
